import BaseController from "../../base.js";
import Mock from "mockjs";

/**
 *
 * @ignore
 * 生成数据库模拟数据，用于测试
 */
export default class extends BaseController {
  /**
   * 执行生成模拟数据的动作
   */
  async runAction() {
    await this.users();
    return this.success("模拟数据生成成功");
  }

  /**
   * 用户信息
   */
  async users() {
    const date = require("silly-datetime");
    const now_date = date.format(new Date() , 'YYYY-MM-DD HH:mm:ss');


    const mockOptions = {
      "list|20": [
        {
          "id|+1": 1,
          account: 1,
          password: "11",
          uname: "@cname()",
          contact_information: "123",
          create_time: now_date,
          permission : "1",
          status: "1",
        },
      ],
    };

    let data = Mock.mock(mockOptions);
    await this.model("users").where(true).delete();
    await this.model("users").addMany(data.list);
  }
}
